#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project : gtmsAutoTestProject 
@File    : base_miniProgram_api.py
@IDE     : PyCharm 
@Author  : Mario
@Date    : 2022/4/25 19:03 
@Describe: 小程序接口请求基类
"""
from APIs.base_api import BaseApi
from Config.yamlRead import miniProgramInfo_cfg
from Comm.tools.toolsControl import ToolsHandler


class BaseMiniProgramApi(BaseApi):
    def __init__(self, brandCode, environment, token):
        """
        构造函数
        :param brandCode: 品牌编码
        :param environment: 环境
        :param token: 用户token
        """
        super().__init__()  # 继承父类构造函数
        self.url = miniProgramInfo_cfg[brandCode][environment]  # 取出配置文件URL前缀
        self.token = token  # 用户token
        self.type = "小程序"

    def get_headers(self) -> object:
        """
        获取小程序接口请求头
        :return:
        """
        timestamp = ToolsHandler.get_timestamp()
        headers = {
            'Connection': 'keep-alive',
            'x-http-token': self.token,
            'x-http-timestamp': timestamp,
            'x-http-devicetype': 'WechatMiniProgram',
            'x-http-channel': '5',
            'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1 wechatdevtools/1.05.2111300 MicroMessenger/8.0.5 webview/',
            'x-http-version': '5.2.4',
            'content-type': 'application/json',
            'Accept': '*/*',
            'Sec-Fetch-Site': 'cross-site',
            'Sec-Fetch-Mode': 'cors',
            'Sec-Fetch-Dest': 'empty',
            'Referer': 'https://servicewechat.com/wx765e46cdab92a0df/devtools/page-frame.html',
            'Cookie': 'SERVERID=k8s-ingress.gtmsh.com:10080'
        }
        return headers


if __name__ == '__main__':
    test = BaseMiniProgramApi('823882', 'sit', '6454ed08-c380-4580-91c3-aee32b168302')
    url = 'customer/code'
    payload = '{}'
    test.http_requests(url, payload)
